package com.coocaa.ops.admin.v1.timedtask.job.listener;


import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.listeners.JobListenerSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author bijiahao
 * @date : 2017/12/18.
 * @description监听 定时任务完成
 */
public class TimelyShelvesJobListener extends JobListenerSupport {
    private static final Logger log = LoggerFactory.getLogger(TimelyShelvesJobListener.class);

    protected String myJobName;
    private Scheduler scheduler;

    public TimelyShelvesJobListener(String jobName, Scheduler scheduler) {
        this.myJobName = jobName;
        this.scheduler = scheduler;
    }

    @Override
    public String getName() {
        return myJobName;
    }

    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        try {
            this.scheduler.deleteJob(context.getJobDetail().getKey());
            log.info("===== jobWasExecuted");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
